/*
 * Copyright (c) 2018. J4dream created
 */

package com.j4dream.property.javabasic.designpattern.singleton;

import java.util.concurrent.atomic.AtomicInteger;

public class SingletonDemo implements Runnable{

    public static void main(String[] args) {

        SingletonDemo singletonDemo = new SingletonDemo();
        Thread t1 = new Thread(singletonDemo);
        Thread t2 = new Thread(singletonDemo);
        Thread t3 = new Thread(singletonDemo);
        Thread t4 = new Thread(singletonDemo);
        Thread t5 = new Thread(singletonDemo);

        t1.start();
        t2.start();
        t3.start();
        t4.start();
        t5.start();
        // 重复调用会 IllegalThreadStateException
        // t4.start();

        AtomicInteger i = new AtomicInteger(0);
        i.incrementAndGet();
    }

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + "__" + Singleton.getIns());
    }
}
